package com.aura.bookshop.controller;

import com.aura.bookshop.entity.User;
import com.aura.bookshop.service.UserService;
import com.aura.bookshop.service.impl.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    UserService userService;

    @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
    public String login(User user, Map<String,Object> map, HttpSession session){

        User u = userService.login(user);
        if(u == null){//登录失败
            map.put("msg","请先登录");
            return "index";
        }else{

            session.setAttribute("user",u.getUsername());
//            return "forward:/book/queryAll";
            return "forward:/teacher/list/1";  //转发
        }




    }


    @RequestMapping("/list")
    public String list(){

        return "ajax_user_list";
    }


}
